home *** CD-ROM | disk | FTP | other *** search
- Path: news.kei.com!ub!newserve!rebecca!rpi!not-for-mail
- From: janc@pi.net (Jan Cornelis)
- Newsgroups: comp.lang.c++,comp.lang.c++.leda,comp.lang.c++.moderated
- Subject: Trees !, Who can help me to improve my trees code ! <janc@pi.net>
- Date: 20 Jan 1996 14:16:25 -0000
- Organization: Planet Internet
- Sender: cppmods@netlab.cs.rpi.edu
- Approved: devitto@ferndown.ate.slb.com
- Message-ID: <4dqtfp$ip5@netlab.cs.rpi.edu>
- NNTP-Posting-Host: netlab.cs.rpi.edu
- X-Original-Date: Sat, 20 Jan 1996 19:52:13 GMT
-
- Who can help me with the following code written. The code doesn't work
- properly. I cannot understand why it doesn't work and how it should be
- improved. Is somebody there capable to help me out correcting this
- code ?
- Then i would like you to ask to help me either with a function in
- searching through the tree !
-
- My e-mail adress: janc@pi.net
-
- #include<stdio.h>
- class jc
- {
- public:
- jc()
- {
- tail=NULL;
- count = 0;
- }
-
- // This function should add a value to the tree !
- void addtree(int p);
-
- // This function should print one value from the tree one by one !
- void onefurther();
-
- private:
- struct list
- {
- // 'e' is the integer number for the tree !
- int e;
- // The left side of the tree
- list *left;
- // The right side of the tree
- list *right;
- };
-
- int count;
- list *tail;
- };
-
- void jc::addtree(int p)
- {
- if (tel==0)
- {
- tailt = new list;
- tail->links=NULL;
- tail->rechts=NULL;
- tailt=NULL;
- tail->e=p;
- tel++;
- }
- else
- {
- if (p < tail->e)
- {
- if (tail->left!=NULL)
- {
- tail->left = new list;
- tail = tail->left;
- }
- else
- {
- tail = tail-> right;
- }
- }
- else
- {
- if (tail->right != NULL)
- {
- tail->right = new list;
- tail = tail->right;
- }
- else
- {
- tail = tail->right;
- }
- }
- tail->left = NULL;
- tail->right = NULL;
- tail->e=p;
- }
- }
-
- void jc::onefurther()
- {
- tail = tail->left;
- printf("\nThe value = %i",staart->e);
- tail = tail->right;
- }
-
- void main()
- {
- jc a;
-
- for (int i=1;i <= 6;i++)
- a.addtail(i);
-
- for (int i=1;i <= 6;i++)
- a.onefurther();
- }
-
-
-
- [ Articles to moderate: mailto:c++-submit@netlab.cs.rpi.edu ]
- [ Read the C++ FAQ: http://www.connobj.com/cpp/cppfaq.htm ]
- [ Moderation policy: http://www.connobj.com/cpp/guide.htm ]
- [ Comments? mailto:c++-request@netlab.cs.rpi.edu ]
-